layui.use('jquery', function() {
    let $ = layui.jquery;
    //1.拼接url
    $.ajaxPrefilter(function(options) {
        options.url = 'http://api-breakingnews-web.itheima.net' + options.url;

        let token = localStorage.getItem('token');
        //2.为需要验证的api添加headers
        if (options.url.indexOf('/my/') != -1) {
            options.headers = {
                Authorization: token

            };
        }
        //3.进行权限统一处理
        options.complete = function(result) {
            //此处的result返回的是一个xmlhttprequest对象，所以result.responseJSON等同于success的result
            if (result.responseJSON.status != 0) {
                //权限验证失败
                location.href = 'login.html';
            }
        }



    })



})
